const path = require('path')
const fs = require('fs')
const fse = require('fs-extra')
const resolve = p => {
  return path.resolve(__dirname, p)
}

if (fse.pathExistsSync(resolve('.broswer'))) {
  fse.removeSync(resolve('.broswer'))
}

const pageSource = resolve('./src/pages')
const entry = {}
fs.readdirSync(pageSource).forEach(name => {
  entry[`js/${name}`] = `${pageSource}/${name}/index.js`
})

module.exports = {
  mode: 'production',
  entry,
  output: {
    path: resolve('.broswer'),
    libraryTarget: 'umd'
  },
  // devtool: 'source-map',
  devServer: {
    port: 7000,
    host: '0.0.0.0',
    hot: false,
    contentBase: resolve('.broswer')
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      }
    ]
  }
}
